<?php


namespace app\cms\model;


use app\cms\community\lib\QueryModel;

class saveSmsModel extends QueryModel
{

    protected $table = "save_sms_table";

    private string $error = "";

    /**
     * 获取单条短信数据并验证数据是否正确
     * @param string $uuid
     * @param int|string $code
     * @param string $to
     * @return saveSmsModel
     */
    public function getSmsLine(string $uuid, int|string $code, string $to): static
    {
        $sms = $this->where([
            'uuid' => $uuid
        ]) -> findOrEmpty();

        if (!$sms -> exists()) {
            $this->error = "验证码不存在";
        }

        if (time() > $sms['expire_time']) {
            $this->error = "验证码已过期";
        }

        if ($code !== $sms['sms_send_code'] && $to !== $sms['email_or_phone']) {
            $this->error = "验证码错误";
        }

        return $this;
    }

    /**
     * @return string
     */
    public function getError(): string
    {
        return $this->error;
    }

}